/**
 * amis v2.4.0
 * Copyright 2018-2022 baidu
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var tslib = require('tslib');
var React = require('react');
var amisCore = require('amis-core');
var amisUi = require('amis-ui');
var StaticHoc = require('./StaticHoc.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

var LocationControl = /** @class */ (function (_super) {
    tslib.__extends(LocationControl, _super);
    function LocationControl() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.domRef = React__default["default"].createRef();
        _this.state = {
            isOpened: false
        };
        return _this;
    }
    LocationControl.prototype.close = function () {
        this.setState({
            isOpened: false
        });
    };
    LocationControl.prototype.open = function () {
        this.setState({
            isOpened: true
        });
    };
    LocationControl.prototype.handleClick = function () {
        this.state.isOpened ? this.close() : this.open();
    };
    LocationControl.prototype.getParent = function () {
        var _a;
        return (_a = this.domRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
    };
    LocationControl.prototype.getTarget = function () {
        return this.domRef.current;
    };
    LocationControl.prototype.renderStatic = function (displayValue) {
        var _a;
        if (displayValue === void 0) { displayValue = '-'; }
        var _b = this.props, cx = _b.classnames, value = _b.value, vendor = _b.vendor, ak = _b.ak, coordinatesType = _b.coordinatesType, popOverContainer = _b.popOverContainer;
        var __ = this.props.translate;
        if (!value) {
            return React__default["default"].createElement(React__default["default"].Fragment, null, displayValue);
        }
        return (React__default["default"].createElement("div", { className: this.props.classnames('LocationControl'), ref: this.domRef },
            React__default["default"].createElement("span", null, value.address),
            React__default["default"].createElement("a", { className: cx('LocationPicker-toggler', 'ml-1'), onClick: this.handleClick },
                React__default["default"].createElement(amisUi.Icon, { icon: "location", className: "icon" })),
            React__default["default"].createElement(amisCore.Overlay, { target: this.getTarget, container: popOverContainer || this.getParent, rootClose: false, show: this.state.isOpened },
                React__default["default"].createElement(amisCore.PopOver, { className: cx('LocationPicker-popover'), onHide: this.close, overlay: true, style: { width: (_a = this.getTarget()) === null || _a === void 0 ? void 0 : _a.offsetWidth } }, vendor === 'baidu' ? (React__default["default"].createElement(amisUi.BaiduMapPicker, { ak: ak, value: value, coordinatesType: coordinatesType })) : (React__default["default"].createElement(amisUi.Alert2, null, __('${vendor} 地图控件不支持', { vendor: vendor })))))));
    };
    LocationControl.prototype.render = function () {
        return (React__default["default"].createElement("div", { className: this.props.classnames('LocationControl') },
            React__default["default"].createElement(amisUi.LocationPicker, tslib.__assign({}, this.props, { ak: amisCore.filter(this.props.ak, this.props.data) }))));
    };
    LocationControl.defaultProps = {
        vendor: 'baidu',
        coordinatesType: 'bd09'
    };
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], LocationControl.prototype, "close", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], LocationControl.prototype, "open", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], LocationControl.prototype, "handleClick", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], LocationControl.prototype, "getParent", null);
    tslib.__decorate([
        amisCore.autobind,
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], LocationControl.prototype, "getTarget", null);
    tslib.__decorate([
        StaticHoc.supportStatic(),
        tslib.__metadata("design:type", Function),
        tslib.__metadata("design:paramtypes", []),
        tslib.__metadata("design:returntype", void 0)
    ], LocationControl.prototype, "render", null);
    return LocationControl;
}(React__default["default"].Component));
/** @class */ ((function (_super) {
    tslib.__extends(LocationRenderer, _super);
    function LocationRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    LocationRenderer = tslib.__decorate([
        amisCore.FormItem({
            type: 'location-picker'
        })
    ], LocationRenderer);
    return LocationRenderer;
})(LocationControl));

exports.LocationControl = LocationControl;
